package com.example.bookmall.config;

import com.example.bookmall.interceptors.LoginInterceptors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ComponentScan
//@Configuration这个配置类也需要注入到ioc容器中
//注册拦截器 LoginInterceptors
public class WebConfig implements WebMvcConfigurer {

    //注入拦截器
    @Autowired
    private LoginInterceptors loginInterceptors;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       //登录接口和注册接口不拦截 放行
        registry.addInterceptor(loginInterceptors)
                .excludePathPatterns("/auth/login", "/auth/register", "/api/captcha","/user/logout",
                        "/books/search","/categorys/list","/books/**");

    }
}
